﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Entity.Admin;
using Web.Framework;
using Service;
using Core;

namespace Web.Areas.Admin.Controllers
{
    public class InquiryParameterController : BaseController
    {
        InquiryParameterService inquiryParameterService;
        public InquiryParameterController()
        {
            inquiryParameterService = new InquiryParameterService(db);
        }

        //
        // GET: /Admin/InquiryParameter/

        public ViewResult Index()
        {
            return View(db.InquiryParameters.OrderBy(p => p.OrderIndex).ToList());
        }

        //
        // GET: /Admin/InquiryParameter/Details/5

        public ViewResult Details(string id)
        {
            InquiryParameter inquiryparameter = db.InquiryParameters.Find(id);
            return View(inquiryparameter);
        }

        //
        // GET: /Admin/InquiryParameter/Edit/5

        public ActionResult Edit(string id)
        {
            InquiryParameter inquiryparameter = db.InquiryParameters.Find(id);
            return View(inquiryparameter);
        }

        //
        // POST: /Admin/InquiryParameter/Edit/5

        [HttpPost]
        public ActionResult Edit(InquiryParameter inquiryparameter)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    inquiryParameterService.CreateOrSave(inquiryparameter);
                    this.AddViewMessage("编辑成功");
                }
                catch (Exception ex)
                {
                    this.AddViewMessage(ex);
                    return View(inquiryparameter);
                }
                return RedirectToAction("Index", new { menuId = Request["menuId"] });
            }
            else
            {
                return View();
            }
        }

        //
        // GET: /Admin/InquiryParameter/Delete/5

        public ActionResult Delete(string id)
        {
            InquiryParameter inquiryparameter = db.InquiryParameters.Find(id);
            return View(inquiryparameter);
        }

        //
        // POST: /Admin/InquiryParameter/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(string id)
        {
            InquiryParameter inquiryparameter = db.InquiryParameters.Find(id);
            db.InquiryParameters.Remove(inquiryparameter);
            db.SaveChanges();
            this.AddViewMessage("删除成功");
            return RedirectToAction("Index", new { menuId=Request["menuId"] });
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}